<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    private $view;

    protected function _initViewApp() {
        $this->bootstrap('view');
        $this->view = $this->getResource('view');

        //converte <? para <?php
        $this->view->setUseStreamWrapper(true);

        $this->view->setEscape('htmlentities');
    }

    protected function _initHead() {
        $this->view->doctype('XHTML1_STRICT');
        $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');

        $this->view->headTitle('Clinica');
        $this->view->headTitle()->setSeparator(' - ');
    }

    protected function _initScritp() {
        $this->view->headScript()->appendFile('/theme/default/js/base.js');
        $this->view->headScript()->appendFile('/theme/default/js/dist/picklist/jquery-picklist.min.js');
        $this->view->headScript()->appendFile('/theme/default/js/dist/jquery/ui/jquery-ui-1.8.1.custom.min.js');
        $this->view->headScript()->appendFile('/theme/default/js/dist/meioMask/meioMask.js');
        $this->view->headScript()->appendFile('/theme/default/js/dist/bootstrap/bootstrap.min.js');
        $this->view->headScript()->appendFile('/theme/default/js/dist/flexgrid/flexigrid.pack.js');
    }

    protected function _initTranslator() {
        $translate = new Zend_Translate('Array', APPLICATION_PATH . '/../languages/pt_br/pt_br.php', 'pt_BR');
        Zend_Validate_Abstract::setDefaultTranslator($translate);
    }

    protected function _initStyle() {
        $this->view->headLink()->appendStylesheet('/theme/default/css/reset.css');
        $this->view->headLink()->appendStylesheet('/theme/default/css/accordion.css');
        $this->view->headLink()->appendStylesheet('/theme/default/css/dist/bootstrap/bootstrap.min.css');
        $this->view->headLink()->appendStylesheet('/theme/default/css/dist/flexgrid/flexigrid.pack.css');
        $this->view->headLink()->appendStylesheet('/theme/default/css/dist/jquery/ui/south/jquery-ui-1.8.21.custom.css');
        $this->view->headLink()->appendStylesheet('/theme/default/css/layout.css');
    }

    protected function _initJquery() {
        $this->view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
        //para nao buscar remotamente do google apis
        $this->view->jQuery()->setLocalPath('/theme/default/js/dist/jquery/jquery-1.4.2.min.js')
                ->setUiLocalPath('/theme/default/js/dist/jquery/ui/jquery-ui-1.8.1.custom.min.js')
                ->addJavascriptFile('/theme/default/js/dist/jquery/ui/jquery.ui.datepicker-pt-BR.js');

        ZendX_JQuery::enableView($this->view);
        $this->view->jQuery()->enable();
        $this->view->jQuery()->uiEnable();
    }

    protected function _initRouter() {
        /*$front = Zend_Controller_Front::getInstance();
         $route = new Zend_Controller_Router_Route(
              'index/:mensagem/*',
              array(
                  'controller'    => '',
                  'action'        => 'index'
              )
          );
          $front->getRouter()->addRoute('index', $route); */
    }

    protected function _initHelpers(){
        $this->view->addHelperPath("../plugins/helpers", "Zend_Aquiles_Helpers");
    }
    
    protected function _initLocale() {
        $locale = new Zend_Locale('pt_BR');
        Zend_Registry::set('Zend_Locale', $locale);
    }

    protected function _initLoader() {
        $loaderPlugin = new Zend_Loader_Autoloader_Resource(array(
                    'basePath' => APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
                    'namespace' => 'Plugin'
                ));
        $loaderPlugin->addResourceTypes(array(
            'helper' => array(
                'namespace' => 'Helper',
                'path' => 'helpers'
            )
        ));

        $loaderPlugin = new Zend_Loader_Autoloader_Resource(array(
                    'basePath' => APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'utils' . DIRECTORY_SEPARATOR,
                    'namespace' => 'Util'
                ));
        $loaderPlugin->addResourceTypes(array(
            'functions' => array(
                'namespace' => 'Function',
                'path' => 'functions'
            )
        ));

        $loaderPlugin->addResourceTypes(array(
            'implementations' => array(
                'namespace' => 'Implementation',
                'path' => 'implementations'
            )
        ));
    }

    protected function _initActionHelpers() {
        $sessionHelper = new Plugin_Helper_Session();
        Zend_Controller_Action_HelperBroker::addHelper($sessionHelper);
    }

    protected function _initDefaultDb() {
        $db = Zend_Db::factory('Pdo_Mysql', array(
                    'host' => '127.0.0.1',
                    'username' => 'fisio',
                    'password' => 'fisio',
                    'dbname' => 'sistema'
                ));
        Zend_Db_Table::setDefaultAdapter($db);
    }
    
    protected function _initPlugins() {
        $front = Zend_Controller_Front::getInstance();

        //layout
        $pluginLayout = new Zendlay_Layout();
        $front->registerPlugin($pluginLayout);

        //acl
        $auth = Zend_Auth::getInstance();
        $acl = new MyAcl($auth);

        //auth
        $aclPlugin = new AclPlugin($auth, $acl);

        $front->registerPlugin($aclPlugin);
    }
}